<?php
class Application_Model_topUpAlipay extends Application_Model_DomainObject implements Application_Model_PayInterface {

	protected $_id;

	protected $_amount;

	protected $_dateCreated;

	protected $_serviceFee;

	protected $_status;

	protected $_userId;

	protected $_dateProcee;

	protected $_realname;
        
        protected $_useraccount;
        
        const STATUS_WaitPay = 0; // 待付款
    
        const STATUS_Processing = 1;//已付款

        const STATUS_Sended = 10;//已处理

        const STATUS_Refund = -1;//退款
	/**
	 * 服务费用
	 */
	public static function GetServiceMoney()
	{
		return Application_Model_Config::getProcessFee()->Value;
	}

	public static function getDb(){
		return new Application_Model_DbTable_topUpAlipay();
	}
	
	public static function getTopUpAlipayById($id)
	{
		return Application_Model_topUpAlipay::getDb()->queryOne(array('id'=>$id));
	}
    
    public function getMoney() {
        return $this->_amount + $this->_serviceFee;
    }
    
    public function getPayMoney(){
        return $this->_amount;
    }


    public function getPayName() {
        return '代充值';
    }
    
    public function canPay($userId) {
        if($this->_userId != $userId)
            return FALSE;
        if($this->_status ==Application_Model_PayBill::PAY_STATUS_SUCCESS)
            return FALSE;
        return TRUE;
    }
    
    public function setPaid() {
        $this->_status = Application_Model_PayBill::PAY_STATUS_SUCCESS;
    }
    
    public function getBillNo() {
        return $this->_id;
    }
    
    public function getPayDescription() {
        return '悠奇代充值服务，充值到支付宝，用户名:'.Application_Model_User::load($this->_id)->Email;
    }
    public static function getcountchargr($status = null)
    {
        if($status === null){
            $where[' dateCreated >='] = date('Y-m-d');
        }else{
            $where[' status = '] = $status;
        }
        return Application_Model_topUpAlipay::getDao()->count($where);
    }
    public static function getByFilter($username,$status,$day,$count, $offset) {
        $where = array();
        $and = '';

        $hasUserCon = false;

        $user_where = " 1=1 ";
        if ($username != NULL) {
            $hasUserCon = true;
            $user_where .= " and nikename = '$username' ";
        }

        if ($hasUserCon) {
            //查询用户
            $array_user = Application_Model_User::getDao()->fetchRow($user_where);
            if ($array_user) {
                $where['userid = '] = $array_user->id;
                $and = ' and ';
            } else {
                return NULL;
            }
        }
        if($status != ""){
            $where[$and.' status = '] = $status;
            $and = ' and ';
        }else{
            if($day == 1){
                $where[$and.' dateCreated >='] = date('Y-m-d');
                $and = ' and ';
            }
        }
        return Application_Model_topUpAlipay::getDb()->queryPage($where, " dateCreated desc", $count, $offset);
    }
    public function getstatuscaption() {
        switch ($this->_status) {
            case "0";
                return '待付款';
            case "1";
                return '已付款';
            case "10";
                return '已处理';
            case "-1":
                return "已退款";
        }
    }
    public function getuserinfo() {
        if ($this->_userId) {
            return Application_Model_User::load($this->_userId);
        }
    }
}